﻿package game 
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import game.events.EventData;
	/**
	 * ...
	 * @author Nguyen Thi Bich Phuong (Daisy)
	 */
	public class ChipController3BAC extends ChipController {		
		public function ChipController3BAC() { 
		}		
		override public function initChipsValue(value:int):void {
			var xPos:int = chip0.x;
			var yPos1:int = chip0.y;
			var yPos2:int = chip0.y + 66;
			var dis:int = value;
			for (var i = 0; i < this.chipValueArrText.length; i++) {
				var chip:Chip;
				if (i > 0) {
					chip = new Chip();
					this.addChild(chip);
					chip.transform = this.chip0.transform;					
					chip.x = xPos;					
					if(i%6 < 3) {
						chip.y = yPos1;
					} else {
						chip.y = yPos2;
					}
				}else {
					chip = this.chip0;					
				}				
				chip.chipName = "Chip" + i;
				chip.setFrameIndex(i%6 * 3 + 1);
				chip.valueTf.text = this.chipValueArrText[i] + "";				
				chip.value = Number(this.chipValueArr[i]);
				chip.addEventListener(MouseEvent.MOUSE_DOWN, chipMouseDownHdl);
				this.chipArr.push(chip);
				if (i % 6 == 2) {					
					xPos -= (dis * 2);
				} else {
					xPos += dis;
				}
			}		
			this.activeChip = this.chip0;
		}
		
		override public function chipMouseDownHdl(e:MouseEvent):void {
			/*
			if (e.currentTarget != this.activeChip) {
				this.activeChip.unActive();
				this.activeChip = Chip(e.currentTarget);
			}
			var event:KenoEvent = new KenoEvent(KenoEvent.CHIP_CLICK, true);
			dispatchEvent(event);
			
			*/	
						
			if (e.currentTarget != this.activeChip) {
				this.activeChip.unActive();
				this.activeChip = Chip(e.currentTarget);		
				
				var event:EventData = new EventData(EventData.CHIP_ACTIVE, true);
				event.chipActive = this.activeChip.chipName;					
				dispatchEvent(event);
			}
		}
		
	}
}